package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocEndowmentInsurancecacheDao;
import com.irdstudio.cdp.pboc.service.domain.PbocEndowmentInsurancecache;
import com.irdstudio.cdp.pboc.service.facade.PbocEndowmentInsurancecacheService;
import com.irdstudio.cdp.pboc.service.vo.PbocEndowmentInsurancecacheVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 养老保险金缴存记录				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocEndowmentInsurancecacheService")
public class PbocEndowmentInsurancecacheServiceImpl implements PbocEndowmentInsurancecacheService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocEndowmentInsurancecacheServiceImpl.class);

	@Autowired
	private PbocEndowmentInsurancecacheDao pbocEndowmentInsurancecacheDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocEndowmentInsurancecache(PbocEndowmentInsurancecacheVO inPbocEndowmentInsurancecacheVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocEndowmentInsurancecacheVo.toString());
		int num = 0;
		try {
			PbocEndowmentInsurancecache pbocEndowmentInsurancecache = new PbocEndowmentInsurancecache();
			beanCopy(inPbocEndowmentInsurancecacheVo, pbocEndowmentInsurancecache);
			num = pbocEndowmentInsurancecacheDao.insertPbocEndowmentInsurancecache(pbocEndowmentInsurancecache);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocEndowmentInsurancecacheVO inPbocEndowmentInsurancecacheVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocEndowmentInsurancecacheVo);
		int num = 0;
		try {
			PbocEndowmentInsurancecache pbocEndowmentInsurancecache = new PbocEndowmentInsurancecache();
			beanCopy(inPbocEndowmentInsurancecacheVo, pbocEndowmentInsurancecache);
			num = pbocEndowmentInsurancecacheDao.deleteByPk(pbocEndowmentInsurancecache);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocEndowmentInsurancecacheVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocEndowmentInsurancecacheVO inPbocEndowmentInsurancecacheVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocEndowmentInsurancecacheVo.toString());
		int num = 0;
		try {
			PbocEndowmentInsurancecache pbocEndowmentInsurancecache = new PbocEndowmentInsurancecache();
			beanCopy(inPbocEndowmentInsurancecacheVo, pbocEndowmentInsurancecache);
			num = pbocEndowmentInsurancecacheDao.updateByPk(pbocEndowmentInsurancecache);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocEndowmentInsurancecacheVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocEndowmentInsurancecacheVO queryByPk(PbocEndowmentInsurancecacheVO inPbocEndowmentInsurancecacheVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocEndowmentInsurancecacheVo);
		try {
			PbocEndowmentInsurancecache queryPbocEndowmentInsurancecache = new PbocEndowmentInsurancecache();
			beanCopy(inPbocEndowmentInsurancecacheVo, queryPbocEndowmentInsurancecache);
			PbocEndowmentInsurancecache queryRslPbocEndowmentInsurancecache = pbocEndowmentInsurancecacheDao.queryByPk(queryPbocEndowmentInsurancecache);
			if (Objects.nonNull(queryRslPbocEndowmentInsurancecache)) {
				PbocEndowmentInsurancecacheVO outPbocEndowmentInsurancecacheVo = beanCopy(queryRslPbocEndowmentInsurancecache, new PbocEndowmentInsurancecacheVO());
				logger.debug("当前查询结果为:"+ outPbocEndowmentInsurancecacheVo.toString());
				return outPbocEndowmentInsurancecacheVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocEndowmentInsurancecacheVO> queryAllOwner(PbocEndowmentInsurancecacheVO pbocEndowmentInsurancecacheVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocEndowmentInsurancecacheVO> list = null;
		try {
			List<PbocEndowmentInsurancecache> pbocEndowmentInsurancecaches = pbocEndowmentInsurancecacheDao.queryAllOwnerByPage(pbocEndowmentInsurancecacheVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocEndowmentInsurancecaches.size());
			pageSet(pbocEndowmentInsurancecaches, pbocEndowmentInsurancecacheVo);
			list = (List<PbocEndowmentInsurancecacheVO>) beansCopy(pbocEndowmentInsurancecaches, PbocEndowmentInsurancecacheVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocEndowmentInsurancecacheVO> queryAllCurrOrg(PbocEndowmentInsurancecacheVO pbocEndowmentInsurancecacheVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocEndowmentInsurancecache> pbocEndowmentInsurancecaches = pbocEndowmentInsurancecacheDao.queryAllCurrOrgByPage(pbocEndowmentInsurancecacheVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocEndowmentInsurancecaches.size());
		List<PbocEndowmentInsurancecacheVO> list = null;
		try {
			pageSet(pbocEndowmentInsurancecaches, pbocEndowmentInsurancecacheVo);
			list = (List<PbocEndowmentInsurancecacheVO>) beansCopy(pbocEndowmentInsurancecaches, PbocEndowmentInsurancecacheVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocEndowmentInsurancecacheVO> queryAllCurrDownOrg(PbocEndowmentInsurancecacheVO pbocEndowmentInsurancecacheVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocEndowmentInsurancecache> pbocEndowmentInsurancecaches = pbocEndowmentInsurancecacheDao.queryAllCurrDownOrgByPage(pbocEndowmentInsurancecacheVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocEndowmentInsurancecaches.size());
		List<PbocEndowmentInsurancecacheVO> list = null;
		try {
			pageSet(pbocEndowmentInsurancecaches, pbocEndowmentInsurancecacheVo);
			list = (List<PbocEndowmentInsurancecacheVO>) beansCopy(pbocEndowmentInsurancecaches, PbocEndowmentInsurancecacheVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

	/**
	 * 通过fId查询养老金记录: <br>
	 * 0.1:caoxin:2019/5/9 16:10: <br>
	 * @author caoxin
	 * @return
	 * @since 2019/5/9 16:10
	 * @date 2019/5/9 16:10
	 * @version 0.1
	 */
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:通过fId查询养老金记录
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响实际业务
//	@SuppressWarnings("unchecked")
//	public List<PbocEndowmentInsurancecacheVO> queryByReportId(PbocEndowmentInsurancecacheVO pbocEndowmentInsurancecacheVo)  throws Exception {
//
//		logger.debug("通过征信报告编号查询养老金:");
//		List<PbocEndowmentInsurancecacheVO> list = null;
//		try {
//			List<PbocEndowmentInsurancecache> pbocEndowmentInsurancecaches = pbocEndowmentInsurancecacheDao.queryByReportId(pbocEndowmentInsurancecacheVo);
//			logger.debug("通过征信报告编号查询养老金数量为:"+ pbocEndowmentInsurancecaches.size());
//			pageSet(pbocEndowmentInsurancecaches, pbocEndowmentInsurancecacheVo);
//			list = (List<PbocEndowmentInsurancecacheVO>) beansCopy(pbocEndowmentInsurancecaches, PbocEndowmentInsurancecacheVO.class);
//		} catch (Exception e) {
//			logger.error("数据转换出现异常!", e);
//			throw e;
//		}
//		
//		return list;
//	
//	}


}

